<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="${ctx}/static/lib/layui/css/layui.css">
</head>
<style type="text/css">
	.main_div{
		margin : 15px;
	}
</style>

<body>

<form class="layui-form layui-form-pane" action="" id="form_add">
  <div class="layui-form-item">
    <label class="layui-form-label">机会来源</label>
    <div class="layui-input-block">
    <!--lay-verify="required" 这个语句是自带的正则表达式，包含的意思是 该文本框不能为空(必填项) -->
      <input type="text" name="chanceSource" lay-verify="required" autocomplete="off" placeholder="" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">所属客户ID</label>
    <div class="layui-input-inline">
      <select id="customerId" name="customerId">
     </select>
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">意向产品ID</label>
    <div class="layui-input-inline">
      <select id="productId" name="productId" >
     </select>
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">指派销售人员ID</label>
   <div class="layui-input-inline">
      <select id="userId" name="userId" >
      </select>
    </div>
  </div>
  
   <div class="layui-form-item">
    <label class="layui-form-label">成功几率</label>
    <div class="layui-input-block">
      <input type="text" name="successRate" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
    </div>
  </div>
  
   <div class="layui-form-item">
    <label class="layui-form-label">机会描述</label>
    <div class="layui-input-block">
      <input type="text" name="description" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
    </div>
  </div>
   <div class="layui-form-item">
   <!--创建人下拉框  -->
   <!--创建人应该写一个隐藏的input，谁登录就是谁创建  -->
  <label class="layui-form-label">创建人</label>
    <div class="layui-input-inline">
      <select id="" name="" >
      </select>
    </div>
   </div>
  <!--提交按钮开始 -->
  <div class="layui-form-item">
    <input class="layui-btn" onclick="submitForm()" lay-filter="demo2" value="添加" />
  </div>
</form>
  <!--提交按钮结束 -->
          
<script src="${ctx}/static/back/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctx}/static/common/mylayer.js"></script>
<script src="${ctx}/static/common/util.js"></script>
<script src="${ctx}/static/lib/layui/layui.js"></script>
<script src="${ctx}/static/lib/kindeditor/kindeditor.js"></script>
<script src="${ctx}/static/lib/kindeditor/lang/zh_CN.js"></script>
<!--layer弹窗测试  -->
<script>
layui.use(['layer'],function() {
	var layer = layui.layer;
});

layui.use(['form', 'upload' ], function(){
	  var form = layui.form;
	 	upload = layui.upload;
	 	//刷新select选择框渲染
	 	form.render('select');
	 	
	 	//加载指派销售人员
	 	$(function(){
	 		$.ajax({
	 			url:"${ctx}/user/selectCreateMan.action",//查询销售人员
	 			type:"post",
	 			dataType:"json",
	 			success:function(resp) {
	 				if (resp.code == util.SUCCESS) {
	 					var html = "<option value=''>请指派销售人员</option>";
	 					var data = resp.data;
	 					for (var i=0;i<data.length;i++) {
	 						//字符串拼接
	 						html += "<option value='"+data[i].id+"'>"+data[i].name+"</option>"
	 					}
	 					$("#userId").html(html);
	 					form.render('select');
	 				}
	 			}
	 		});
	 	});
	 
	 	//加载商品分类
	 		$.ajax({
	 			url:"${ctx}/product/selectProductId.action",
	 			type:"post",
	 			dataType:"json",
	 			success:function(resp) {
	 				if (resp.code == util.SUCCESS) {
	 					var html = "<option value=''>请选择意向产品ID</option>";
	 					var data = resp.data;
	 					for (var i=0;i<data.length;i++) {
	 						//字符串拼接
	 						html += "<option value='"+data[i].id+"'>"+data[i].name+"</option>"
	 					}
	 					$("#productId").html(html);
	 					form.render('select');
	 				}
	 			}
	 		});
	 
	 	
	 	//加载所属客户ID
	 		$.ajax({
	 			url:"${ctx}/customer/selectCustomerId.action",
	 			type:"post",
	 			dataType:"json",
	 			success:function(resp) {
	 				if (resp.code == util.SUCCESS) {
	 					var html = "<option value=''>请选择所属客户ID</option>";
	 					var data = resp.data;
	 					for (var i=0;i<data.length;i++) {
	 						//字符串拼接
	 						html += "<option value='"+data[i].id+"'>"+data[i].name+"</option>"
	 					}
	 					$("#customerId").html(html);
	 					form.render('select');
	 				}
	 			}
	 		});
	 	});
	 	
		function submitForm() {
			//ajax方式提交表单
			$.ajax({
				url:"${ctx}/salechance/insert.action",
				//data提交，序列化
				data:$('#form_add').serialize(),
				type:"POST",
				dataType:"json",
				success :function (resp) {
					if (resp.code == util.SUCCESS) {
						mylayer.confirm("添加成功，是否跳转到列表界面？","${ctx}/salechance/getPage.action");
					}else{
						mylayer.errorMsg(resp.msg);					
					}
				}
			}); 
		}
	
</script>
</body>
</html>